#!/usr/bin/env node
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var watchfile = /** @class */ (function () {
    function watchfile() {
        this.index = 0;
        this.callbackobj = {};
    }
    Object.defineProperty(watchfile, "instance", {
        get: function () {
            if (!this._instance) {
                this._instance = new watchfile();
            }
            return this._instance;
        },
        enumerable: true,
        configurable: true
    });
    watchfile.prototype.watchchange = function (path, callback, thisobj) {
        var _this = this;
        this.index++;
        var call = function (path1) {
            var tt = new watchobj(path1, _this.index, _this.getfilechange, _this);
            _this.callbackobj[_this.index].fsobj.push(tt);
        };
        if (!this.callbackobj[this.index]) {
            this.callbackobj[this.index] = {
                callback: callback,
                thisobj: thisobj,
                fsobj: []
            };
        }
        ;
        var call1 = function (path2) {
            call(path2);
            if (!fs.statSync(path2).isFile()) {
                var list = fs.readdirSync(path2);
                list.forEach(function (element, index) {
                    var str = path2 + "/" + element;
                    str = str.replace(/\\+/g, "/");
                    call1(str);
                }, _this);
            }
        };
        call1(path);
        return this.index;
    };
    watchfile.prototype.getfilechange = function (type, filename, index) {
    };
    watchfile.prototype.off = function (index) {
        if (this.callbackobj[index] && this.callbackobj[index].fsobj) {
            for (var i = 0; i < this.callbackobj[index].fsobj.length; i++) {
                var data = this.callbackobj[index].fsobj[i];
                data.fswatch.removeAllListeners();
            }
        }
        delete this.callbackobj[index];
    };
    watchfile._instance = null;
    return watchfile;
}());
exports.watchfile = watchfile;
var watchobj = /** @class */ (function () {
    function watchobj(path, index, callback, thisobj) {
        var _this = this;
        this.path = path;
        this.type = index;
        this.callback = callback;
        this.thisobj = thisobj;
        this.fswatch = fs.watch(path, function (type1, filename) {
            if (_this.callback) {
                _this.callback.call(_this.thisobj, type1, _this.path, _this.type);
            }
        });
        return this;
    }
    return watchobj;
}());
exports.watchobj = watchobj;
// console.log(watchfile.instance.show())
